#include <bits/stdc++.h>

#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define in read()
#define rep(i, x, y) for(int i = (x); i <= (y); i++)
#define per(i, x, y) for(int i = (x); i >= (y); i--)

using namespace std;

using ll = long long;
using db = double;
using pii = pair < int, int >;
using vec = vector < int >;
using veg = vector < pii >;

int read() {
	int x = 0; bool f = 0; char ch = getchar();
	while(!isdigit(ch)) f |= ch == '-', ch = getchar();
	while(isdigit(ch)) x = x * 10 + (ch ^ 48), ch = getchar();
	return f ? -x : x;
}

const int N = 1e5 + 10;

ll s[N], f[N];
int n, h[N], w[N];
int mxh;

namespace seg {
	const int N = 1e6 + 10;
	struct line {
		ll k, b;
		ll operator [](ll x) { return k * x + b; }
	} val[N << 1];
	int L[N << 1], R[N << 1], md[N << 1], ch[N << 1][2], ndn, rt;
	void build(int &o, int l, int r) {
		o = ++ndn; L[o] = l; R[o] = r; val[o].k = 1e9, val[o].b = 1e18; if(l == r) return; md[o] = (l + r) >> 1;
		build(ch[o][0], l, md[o]); build(ch[o][1], md[o] + 1, r);
	}
	void ins(const int &o, line x) {
		if(val[o][md[o]] > x[md[o]]) swap(x, val[o]);
		if(L[o] == R[o]) return;
		if(val[o][L[o]] > x[L[o]]) ins(ch[o][0], x);
		if(val[o][R[o]] > x[R[o]]) ins(ch[o][1], x);
	}
	int pos;
	ll query(const int &o) {
		if(L[o] == R[o]) return val[o][pos];
		if(pos <= md[o]) return min(query(ch[o][0]), val[o][pos]);
		else return min(query(ch[o][1]), val[o][pos]);
	}
	void init() { build(rt, 0, mxh); }
	void add(ll k, ll b) { seg :: ins(rt, (line){ k, b }); }
	ll qry(int p) { pos = p; return query(rt); }
}

int main() {
#ifndef ONLINE_JUDGE
	freopen("1.in", "r", stdin);
#endif
	n = in; rep(i, 1, n) h[i] = in, mxh = max(mxh, h[i]);
	rep(i, 1, n) w[i] = in, s[i] = s[i - 1] + w[i];
	f[1] = 0; seg :: init(); seg :: add(-2 * h[1], f[1] - s[1] + 1ll * h[1] * h[1]);
	rep(i, 2, n) {
		f[i] = seg :: qry(h[i]) + s[i - 1] + 1ll * h[i] * h[i];
		seg :: add(-2 * h[i], f[i] - s[i] + 1ll * h[i] * h[i]);
	} printf("%lld\n", f[n]);
	return 0;
}
